<?PHP
  $current_page = "user_update.php";
  $page_type = "A";
  require_once 'header.php';
?>
	<div id="page">
	  <div id="page-padding">
        <!-- start content -->	    
	    <div id="content">
	      <div id="content-padding">
            <h1>User Account Update Form</h1>
            <?PHP
              if (!empty($_GET["update_error"]))
                $msg = "<font color=\"#CC0000\">{$_GET["update_error"]}</font>";
              else
                $msg = '';
  
              // Verify where we are from, user.php or user_update_response.php
              if (!isset($_GET["update_error"])) { // From user.php
                // Fetch the account to be updated
                $input_user_id = $_GET["user_id"];

                $sql = "select * from USER_ACCT where UserId='$input_user_id'";

                $result_array = execute_sql_in_oracle($sql);
                $result = $result_array["flag"];
                $cursor = $result_array["cursor"];

                if (!$result){
                  display_oracle_error_message($cursor);
                  die("Query using inputted user account failed.");
                }

                // Get user account information from database query result
                $values = oci_fetch_array($cursor);
                oci_free_statement($cursor);

                $user_id = $values[0];
                $password = $values[1];
                $fname = $values[2];
                $lname = $values[3];
                $dob = $values[4];
                $street = $values[5];
                $city = $values[6];
                $state = $values[7];
                $zip = $values[8];
                $email = $values[9];
                $phone = $values[10];
                $gender = $values[11];
                $promo = $values[12];
                $aflag = $values[13];
                $sflag = $values[14];
                $vflag = $values[15];
  
                // Account type
                if ($aflag == 'y')
                  $account_type = "A";
                else if ($sflag == 'y') 
                  $account_type = "S";
                else if ($vflag == 'y')
                  $account_type = "V";
                else
                  $account_type = "";
              }
              else { // From user_update_response.php
                // Initialize field variables
                $user_id = "";
                $password = "";
                $fname = "";
                $lname = "";
                $dob = "";
                $street = ""; 
                $city = "";
                $state = "";
                $zip = "";
                $email = "";
                $phone = "";
                $gender = "";
                $promo = "";
                $account_type = "";
  
                // Obtain values of the account to be updated directly
                if (isset($_SESSION['input_user_id']))
                  $user_id = $_SESSION['input_user_id'];
                if (isset($_SESSION['input_password']))
                  $password = $_SESSION['input_password'];
                if (isset($_SESSION['input_fname']))
                  $fname = $_SESSION['input_fname'];
                if (isset($_SESSION['input_lname']))
                  $lname = $_SESSION['input_lname'];
                if (isset($_SESSION['input_dob']))
                  $dob = $_SESSION['input_dob'];
                if (isset($_SESSION['input_street']))
                  $street = $_SESSION['input_street']; 
                if (isset($_SESSION['input_city']))
                  $city = $_SESSION['input_city'];
                if (isset($_SESSION['input_state']))
                  $state = $_SESSION['input_state'];
                if (isset($_SESSION['input_zip']))
                  $zip = $_SESSION['input_zip'];
                if (isset($_SESSION['input_email']))
                  $email = $_SESSION['input_email'];
                if (isset($_SESSION['input_phone']))
                  $phone = $_SESSION['input_phone'];
                if (isset($_SESSION['input_promo']))
                  $promo = $_SESSION['input_promo'];
                if (isset($_SESSION['input_gender']))
                  $gender = $_SESSION['input_gender'];
                if (isset($_SESSION['input_account_type']))
                  $account_type = $_SESSION['input_account_type'];
              }

              // Display the account to be updated
              echo("<form method=\"post\" action=\"user_update_response.php\">
                    Username (Read-only): <input type=\"text\" readonly value = \"$user_id\" size=\"20\" maxlength=\"30\" name=\"user_id\"> <br> 
                    Current Password (Required): <input type=\"password\" value = \"$password\" size=\"20\" maxlength=\"30\" name=\"password\">  <br>
                    First Name (Required): <input type=\"text\" value = \"$fname\" size=\"20\" maxlength=\"30\" name=\"fname\">  <br>
                    Last Name (Required): <input type=\"text\" value = \"$lname\" size=\"20\" maxlength=\"30\" name=\"lname\">  <br>
                    DOB(DD-MON-YY): <input type=\"text\" value =\"$dob\" size=\"20\" maxlength=\"9\" name=\"dob\"><br> 
                    Street: <input type=\"text\" value =\"$street\" size=\"20\" maxlength=\"50\" name=\"street\"><br>
                    City: <input type=\"text\" value =\"$city\" size=\"20\" maxlength=\"50\" name=\"city\"><br>
                    State: <input type=\"text\" value =\"$state\" size=\"20\" maxlength=\"50\" name=\"state\"><br>
                    Zip: <input type=\"text\" value =\"$zip\" size=\"20\" maxlength=\"12\" name=\"zip\"><br>
                    E-mail: <input type=\"text\" value =\"$email\" size=\"20\" maxlength=\"50\" name=\"email\"><br>
                    Phone: <input type=\"text\" value =\"$phone\" size=\"20\" maxlength=\"15\" name=\"phone\"><br>");

              // Reselect account type dropdownlist after postback
              if ($account_type=="") {
                $choose_one_select = htmlspecialchars("selected=\"selected\"");
              }
              if ($account_type=="A") {
                $a_selection = htmlspecialchars("selected=\"selected\"");
              }
              if ($account_type=="V") {
                $v_selection = htmlspecialchars("selected=\"selected\"");
              }
              if ($account_type=="S") {
                $s_selection = htmlspecialchars("selected=\"selected\"");
              }

              // Create the dropdown list for the account type
              echo("Account Type:
			        <select name=\"account_type\">
                    <option value=\"\" $choose_one_select>Choose One</option>
                    <option value=\"A\" $a_selection>Administrator</option>
                    <option value=\"S\" $s_selection>Stakeholder</option>
                    <option value=\"V\" $v_selection>Volunteer</option>	
                    </select><br>");
  
              // Reselect gender dropdownlist after postback
              if ($gender=="") 
                $choose_one_select1 = htmlspecialchars("selected");
              else if ($gender=="m") 
                $m_selection = htmlspecialchars("selected");
              else if ($gender=="f") 
                $f_selection = htmlspecialchars("selected");
  
              // Create the dropdown list for the gender
              echo("Gender:
                    <select name=\"gender\">
                    <option value=\"\" $choose_one_select1>Choose One</option>
                    <option value=\"m\" $m_selection>Male</option>
                    <option value=\"f\" $f_selection>Female</option></select><br>");
  
              // Reselect promotion request status dropdownlist after postback
              if ($promo=="") 
                $choose_one_select2 = htmlspecialchars("selected");
              else if ($promo=="y") 
                $yp_selection = htmlspecialchars("selected");
              else if ($promo=="n") 
                $np_selection = htmlspecialchars("selected");
  
              // Create the dropdown list for the promotion request status
              echo("Promotion Request Status:
                    <select name=\"promo\">
                    <option value=\"\" $choose_one_select2>Choose One</option>
                    <option value=\"y\" $yp_selection>Yes</option>
                    <option value=\"n\" $np_selection>No</option></select><br>");

              echo("<input type=\"submit\" value=\"Update\">
                    <input type=\"reset\" value=\"Reset\">
                    </form><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
                    <form method=\"post\" action=\"user.php\">
                    <input type=\"submit\" value=\"Go Back\">
                    </form>$msg");
          ?>
	      </div>
		</div>
	  <!-- end content --></div>
	  <div id="footer">
	    <div id="footer-pad">
	      <div class="line"></div>
		  <!-- footer and copyright notice -->
	      <p>Design by <a href="http://www.steves-templates.com">Steve's free website templates</a>.</p>
		  <!-- end footer and copyright notice -->
	    </div>
	  </div>
	</div>
  </body>
</html>